﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Word = Microsoft.Office.Interop.Word;

namespace WordTemplate2.Pannel
{
    public partial class PictureFootNoteForm : Form
    {
        public int foot_note_type = 0;
        public PictureFootNoteForm()
        {
            InitializeComponent();
            domainUpDown1.SelectedIndex = 0;
        }

        private void button1_Click(object sender, EventArgs e)
        {
            if (foot_note_type == 0)
            {
                object move = Word.WdMovementType.wdMove;
                object extend = Word.WdMovementType.wdExtend;
                object line = Word.WdUnits.wdLine;
                object character = Word.WdUnits.wdCharacter;
                object number = 1;
                object style = "标准文件_脚注引用";

                bool flag = System.Text.RegularExpressions.Regex.IsMatch(domainUpDown1.Text, "[a-z]");
                if (flag && domainUpDown1.Text.Length == 1)
                {
                    Globals.ThisDocument.Application.Selection.TypeText(domainUpDown1.Text);
                    Globals.ThisDocument.Application.Selection.MoveLeft(ref character, ref number, ref extend);
                    Globals.ThisDocument.Application.Selection.set_Style(ref style);
                    this.Visible = false;
                    this.Close();
                }
                else
                {
                    MessageBox.Show("请正确填写脚注编号！");
                }
            }
            else
            {
                object move = Word.WdMovementType.wdMove;
                object extend = Word.WdMovementType.wdExtend;
                object line = Word.WdUnits.wdLine;
                object character = Word.WdUnits.wdCharacter;
                object number = 1;
                object style = "标准文件_段";

                bool flag = System.Text.RegularExpressions.Regex.IsMatch(domainUpDown1.Text, "[a-z]");
                if (flag && domainUpDown1.Text.Length == 1)
                {
                    Globals.ThisDocument.Application.Selection.TypeText(domainUpDown1.Text);
                    Globals.ThisDocument.Application.Selection.MoveLeft(ref character, ref number, ref extend);
                    Globals.ThisDocument.Application.Selection.set_Style(ref style);
                    Globals.ThisDocument.Application.Selection.Font.Superscript = 1;
                    Globals.ThisDocument.Application.Selection.MoveRight(ref character, ref number, ref move);
                    Globals.ThisDocument.Application.Selection.TypeText(" ");
                    Globals.ThisDocument.Application.Selection.MoveLeft(ref character, ref number, ref extend);
                    Globals.ThisDocument.Application.Selection.Font.Superscript = 0;

                    this.Visible = false;
                    this.Close();
                }
                else
                {
                    MessageBox.Show("请正确填写脚注编号！");
                }
            }
        }

        private void button2_Click(object sender, EventArgs e)
        {
            this.Visible = false;
            this.Close();
        }

        private void domainUpDown1_SelectedItemChanged(object sender, EventArgs e)
        {
            if (domainUpDown1.Text.Length > 1)
            {
                domainUpDown1.Text = domainUpDown1.Text.Substring(0, 1);
            }
        }

        private void PictureFootNoteForm_VisibleChanged(object sender, EventArgs e)
        {
            if (this.Visible == true && foot_note_type == 1)
            {
                label2.Visible = false;
                label3.Visible = true;
            }
            else
            {
                label2.Visible = true;
                label3.Visible = false;
            }
        }
    }
}
